import {Injectable} from '@angular/core';
import {Device} from "@ionic-native/device";
import {JPush} from "@jiguang-ionic/jpush";
import {AboutDetailPage} from "../../pages/about-detail/about-detail";

@Injectable()
export class JPushService {

    devicePlatform:string;

    constructor(jPush: JPush,
                device: Device) {
        this.devicePlatform=device.platform;
    }

    openNotification(appCtrl,navCtrl){
        document.addEventListener('jpush.openNotification', (event: any) => {
            let content;
            if (this.devicePlatform == 'Android') {
                content = event.alert;
            } else {  // iOS
                if (event.aps == undefined) { // 本地通知
                    content = event.content;
                } else {  // APNS
                    content = event.aps.alert;
                }
            }
            alert('open notification: ' + JSON.stringify(event));
            console.log(appCtrl.getActiveNav());
            navCtrl.push('AboutDetailPage');
        }, false);
    }

}
